Skip to content

feat: group rows into outline levels in the xlsx and ods writers - #203

Merged
vaceslav merged 13 commits into
mainfrom
feat/197-row-outline
Nov 27, 2026
Merged

vaceslav merged 13 commits into
mainfrom
feat/197-row-outline

Conversation

@vaceslav

@vaceslav vaceslav commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

A sheet can now group its rows the way Excel's and LibreOffice's outline does, so a report whose rows form a hierarchy — a parent row followed by its children — opens collapsible instead of flattened, with the parent's values repeated on every child.

What changes

  • SheetOptions.Outline takes a RowOutline:
    • Levels (1–7) is the deepest level the sheet uses.
    • SummaryRows is Above by default (a parent above its children) or Below.
    • ShownLevels opens the file collapsed to that many levels, counted the way Excel's level buttons count them. Null opens everything.
  • TabularWriter.BeginRow(int outlineLevel) begins a row at a level. BeginRow() begins one at level 0, and so does every header, batch and export row.
  • Refusals:
    • A level outside the declared outline is refused with TabularWriteException write.outline-level, located at the row that would have been written. The row limit is judged first.
    • Invalid options are refused by BeginSheet with ArgumentOutOfRangeException.
    • TabularExportBuilder<T>.Build refuses an outline, because an export has no way to give a level yet.
  • Per format:
    • xlsx: <outlinePr summaryBelow="0"/>, <sheetFormatPr outlineLevelRow>, and outlineLevel / hidden / collapsed on rows.
    • ods: nested table:table-row-group, with table:display="false" on collapsed groups and table:visibility="collapse" on hidden rows.
    • csv and a zip of csv: the outline is ignored. The checks still apply, so code behaves the same against every format.

What a reader of the code would not guess

  • Excel and LibreOffice look for a collapsed group's flag in different rows.
    • Excel reads it from the summary row: the parent, with summary rows above.
    • LibreOffice ignores the summary position in xlsx and reads it from the row after the group.
    • The xlsx writer marks both rows. Where one flag would have to mean two things, Excel wins. That happens on a row after a hidden group whose own children are shown.
    • docs/KNOWN-ISSUES.md lists the shapes in which LibreOffice then shows "−" over hidden rows, and the cases where a collapsed group ends the sheet.
  • ODF has no setting for the summary position. LibreOffice draws its button on the first row of a group.
  • The xlsx writer now encodes each row's text one row later, on every sheet. It used to happen at EndRow; now it happens at the next BeginRow, or when the sheet closes.
    • With summary rows above and ShownLevels, whether a row is collapsed depends on the next row, so that row's start tag has to wait.
    • Deferring the encoding on every sheet keeps the row path of a plain sheet at one added branch.
    • At most one row is held. FlushRecommended may turn true one row later than before.
  • A sheet without an outline is written byte for byte as before. OutlineUnchangedBytesTests pins this for csv, xlsx, ods and zip.

Verified

  • Tests:

    • unit tests for every rule;
    • every outlined xlsx validated against the OOXML schema;
    • a round trip through the cursor and the import;
    • LibreOffice resave tests asserting that it sees the groups collapsed (xlsx with summary rows above and below, and ods).
  • By hand, in Excel for Mac and LibreOffice:

    • levels 0/1/2 open collapsed to level 0, with "+" on every collapsed group;
    • every collapsed group opens on the first click;
    • without ShownLevels the file opens fully expanded.
  • Write speed, on a Hetzner ccx33 (refs.sh, SUITE=write, fastest of 5 alternating passes, branch against main): every scenario is within ±1 %, below the server's ±3 % noise floor, with the same allocation and peak memory. That includes wide sheets of 5,003 columns, where the deferred encoding holds the largest row.

    scenario main branch difference
    csv, 5M × 30 13,120 ms 13,200 ms +0.6 %
    zip of csv, 5M × 30 19,800 ms 19,740 ms −0.3 %
    xlsx, 1M × 30 5,460 ms 5,470 ms +0.2 %
    xlsx styled, 1M × 30 5,550 ms 5,520 ms −0.5 %
    ods, 1M × 30 5,640 ms 5,690 ms +0.9 %
    ods styled, 1M × 30 6,090 ms 6,070 ms −0.3 %
    xlsx wide, 10k × 5,003 6,200 ms 6,200 ms 0.0 % (peak 44 MB both)
    csv wide, 10k × 5,003 4,910 ms 4,910 ms 0.0 %
    ods wide, 10k × 5,003 6,830 ms 6,830 ms 0.0 %

Design: docs/superpowers/specs/2026-11-27-row-outline-design.md; plan: docs/superpowers/plans/2026-11-27-row-outline.md.

Closes #197

Check a row's outline level with one unsigned compare and test the ods
row path with one; leave BeginSheet's clearing of the held row to
CloseSheet, which already leaves none. Name the outline in the BeginSheet
and BeginRow docs.

Pin what the suite left open: an outlined sheet after one that ended in
a hidden group starts without its state (xlsx), a sheet without
ShownLevels after one with it opens expanded (ods), the header heads a
hidden first group (xlsx), and LibreOffice reads an xlsx outline with
summary rows below as it reads one with summary rows above.
Move the row grouping section after the merged ranges it had split from
their heading, and include its example from a compiled sample instead of
an inline block. Word the error code table's write.outline-level row for
a level the sheet does not declare, and amend the design to the row
holding as built, in neutral wording.
# Conflicts:
#	src/TriasDev.Tabular/PublicAPI.Unshipped.txt
@vaceslav
vaceslav merged commit 5b87928 into main Nov 27, 2026
10 checks passed
@vaceslav
vaceslav deleted the feat/197-row-outline branch November 27, 2026 10:54
vaceslav added a commit that referenced this pull request Nov 27, 2026
🤖 I have created a release *beep* *boop*
---


## [0.9.0](v0.8.3...v0.9.0)
(2026-11-27)


### Features

* an option to read csv quotes strictly, refusing what the reader would
otherwise repair
([#199](#199))
([3ba2885](3ba2885))
* group rows into outline levels in the xlsx and ods writers
([#203](#203))
([5b87928](5b87928)),
closes [#197](#197)


### Bug Fixes

* strict csv quoting names where it refuses, stays cancellable and drops
any whitespace around a quoted field
([#202](#202))
([3d4f26b](3d4f26b))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Slava <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Row grouping (outline levels) in the xlsx and ods writers

1 participant